import json
from json import JSONEncoder

import json
import requests
def login():
    url = 'http://shop-xo.hctestedu.com'
    # url = 'http://shop-xo.hctestedu.com?s=/api/user/login'
    headers = {"s": "/api/user/login"}
    params = {"s": "/api/user/login",
              "application": "app"}
    data = {"accounts": "peipei_001", "pwd": "123456", "type": "username"}

    # login_response = requests.post(url=url,headers=headers, data=data, params=params)
    login_response = requests.post(url=url, data=data, params=params)
    print(login_response.text)

    login_res = login_response.text
    json_data = json.loads(login_res)
    res_data = json_data["data"]
    print(json_data)
    res_data = json_data["data"]
    print(res_data)
    res_token = res_data["token"]
    print("返回的token值为:", res_token)
   # return(res_token)

#def add_favorite(res_token):
    url = 'http://shop-xo.hctestedu.com'
    params = {"s": "/api/user/add_favorite",
              "application": "app",
              "token": res_token
              }
    data = {'id':'2'}
    add_favorite_response = requests.post(url=url, params=params, json=data)
    print("商品收藏正确：",add_favorite_response.text)
    print()
#if __name__ == '__main__':
    #res_token = login()
   # print("返回的token值为:",res_token)
    #add_favorite(res_token)


#jason = json.load(login_response.text)
#print(type(jason))
#print(jason[data])
#print (login_response.status_code)